<template>
    <div class="edu-page-warp">
        <InnerBreadcrumb v-model="indexKey" :path="breadPath" :showBack="true" />
        <div v-show="indexKey == '0'">
            <condition-card @reset="reset" @search="onSubmit" label-width="80px">
                <el-row :gutter="24">
                    <!-- <el-col :span="8">
                        <el-form-item :label="$t('label.grade')">
                            <el-date-picker
                                clearable
                                v-model="queryForm.grade"
                                value-format="yyyy"
                                type="year"
                                :placeholder="$t('message.plzSelect')"
                                style="width: 100%"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.college')">
                            <el-select
                                v-model="queryForm.faculty"
                                filterable
                                style="width:100%;height:33px"
                                clearable
                                @change="handleChangeFaculty"
                                multiple
                                collapse-tags
                            >
                                <el-option
                                    v-for="item in options.faculty"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.major')">
                            <el-select
                                v-model="queryForm.profession"
                                filterable
                                style="width:100%;height:33px"
                                clearable
                                multiple
                                collapse-tags
                            >
                                <el-option
                                    v-for="item in options.profession"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.trainingLevel')">
                            <el-select
                                v-model="queryForm.trainingLevel"
                                style="width:100%"
                                clearable
                            >
                                <el-option
                                    v-for="item in options.trainingLevel"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.trainingCategory')">
                            <el-select
                                v-model="queryForm.trainingCategory"
                                style="width:100%"
                                clearable
                            >
                                <el-option
                                    v-for="item in options.trainingCategory"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('dic.degreeType')">
                            <el-select
                                v-model="queryForm.degreeType"
                                style="width:100%"
                                clearable
                                @change="handleChangeFaculty"
                            >
                                <el-option
                                    v-for="item in options.degreeType"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.formLearning')">
                            <el-select
                                v-model="queryForm.formLearning"
                                style="width:100%"
                                clearable
                            >
                                <el-option
                                    v-for="item in options.formLearning"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.enrolMethod')">
                            <el-select
                                v-model="queryForm.enrolMethods"
                                style="width:100%"
                                collapse-tags 
                                clearable
                            >
                                <el-option
                                    v-for="item in options.enrolMethods"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="8">
                        <el-form-item :label="$t('label.grade')">
                            <el-date-picker
                                clearable
                                v-model="queryForm.grade"
                                value-format="yyyy"
                                type="year"
                                :placeholder="$t('message.plzSelect')"
                                style="width: 100%"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.college')">
                            <el-select
                                v-model="queryForm.faculty"
                                filterable
                                style="width:100%;height:33px"
                                clearable
                                @change="handleChangeFaculty"
                                multiple
                                collapse-tags
                            >
                                <el-option
                                    v-for="item in options.faculty"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.major')">
                            <el-select
                                v-model="queryForm.profession"
                                filterable
                                style="width:100%;height:33px"
                                clearable
                                multiple
                                collapse-tags
                            >
                                <el-option
                                    v-for="item in options.profession"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('label.trainingLevel')">
                            <el-select
                                v-model="queryForm.trainingLevel"
                                style="width:100%"
                                clearable
                            >
                                <el-option
                                    v-for="item in options.trainingLevel"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.trainingCategory')">
                            <el-select
                                v-model="queryForm.trainingCategory"
                                style="width:100%"
                                clearable
                            >
                                <el-option
                                    v-for="item in options.trainingCategory"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('dic.degreeType')">
                            <el-select
                                v-model="queryForm.degreeType"
                                style="width:100%"
                                clearable
                                @change="handleChangeFaculty"
                            >
                                <el-option
                                    v-for="item in options.degreeType"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('label.formLearning')">
                            <el-select
                                v-model="queryForm.formLearning"
                                style="width:100%"
                                clearable
                            >
                                <el-option
                                    v-for="item in options.formLearning"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.enrolMethod')">
                            <el-select
                                v-model="queryForm.enrolMethodList"
                                style="width:100%"
                                multiple
                                collapse-tags 
                                clearable
                            >
                                <el-option
                                    v-for="item in options.enrolMethods"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="审核状态">
                            <el-select
                                v-model="queryForm.status"
                                style="width:100%;height:33px"
                                clearable
                                multiple
                                collapse-tags
                            >
                                <el-option
                                    v-for="item in options.approveStatus"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </condition-card>
            <el-card shadow="never">
                <div class="edu-page-title">{{title}}</div>
                <el-row>
                    <el-col :span="4">
                        <el-input
                            v-model="queryForm.keyWord"
                            :placeholder="$t('score.failScoreManage.pleaseInt')"
                            @keyup.enter.native="onSubmit"
                            style="width:200px"
                        >
                            <i
                                class="el-icon-search"
                                slot="suffix"
                                style="margin-top:10px;cursor:pointer"
                                @click="onSubmit"
                            ></i>
                        </el-input>
                    </el-col>
                    <div class="float-right" style="display: flex">
                    <el-button type="primary" @click="handleAgentApply()">新增</el-button>
                    </div>
                </el-row>
                <edu-table
                    :data="students"
                    size="mini"
                    :order="false"
                    :selection="false"
                    style="width:100%;margin-top:12px"
                    @page-change="handleCurrentChange"
                    :total="queryForm.total_"
                    :pageSize="queryForm.pageSize_"
                    :pageNum="queryForm.pageNum_"
                >
                    <el-table-column
                        :label="$t('label.stuCode')"
                        prop="studentId"
                        show-overflow-tooltip
                        width="80"
                    ></el-table-column>
                    <el-table-column
                        :label="$t('label.stuName')"
                        prop="studentName"
                        width="80"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column :label="$t('label.grade')" prop="grade" width="60"></el-table-column>
                    <el-table-column :label="$t('label.college')" show-overflow-tooltip>
                        <template slot-scope="scope">{{ scope.row.facultyI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.major')" show-overflow-tooltip>
                        <template slot-scope="scope">{{ scope.row.professionI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.trainingLevel')" width="80">
                        <template slot-scope="scope">{{ scope.row.trainingLevelI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.trainingCategory')" width="90">
                        <template slot-scope="scope">{{ scope.row.trainingCategoryI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('dic.degreeType')" prop="degreeType" width="80">
                        <template slot-scope="scope">{{ scope.row.degreeTypeI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.formLearning')" width="80">
                        <template slot-scope="scope">{{ scope.row.formLearningI18n }}</template>
                    </el-table-column>
                    <el-table-column
                        :label="$t('label.enrolMethod')"
                        width="80"
                        show-overflow-tooltip
                    >
                        <template slot-scope="scope">{{ scope.row.enrolMethodsI18n }}</template>
                    </el-table-column>
                    <el-table-column label="导师" show-overflow-tooltip>
                        <template slot-scope="scope">{{ scope.row.teacher }}</template>
                    </el-table-column>
                    <el-table-column label="申请时间" show-overflow-tooltip width="100">
                        <template slot-scope="scope">{{scope.row.applyTime}}</template>
                    </el-table-column>
                    <el-table-column :label="tableTitle+'答辩时间'" show-overflow-tooltip width="170">
                        <template slot-scope="scope">{{getFormatData(scope.row.defenseTime)}}</template>
                    </el-table-column>
                    <el-table-column
                        label="研究生院批准时间"
                        show-overflow-tooltip
                        width="170"
                        prop="passTime"
                    ></el-table-column>
                    <el-table-column
                        label="审核状态"
                        prop="statusName"
                        show-overflow-tooltip
                        width="120"
                    ></el-table-column>
                    <el-table-column label="当前处理人" show-overflow-tooltip width="160">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                v-if="scope.row.status>=5 && scope.row.reviewerName"
                                @click="handleReviewGroup(scope.row.reviewer)"
                            >{{scope.row.reviewerName}}({{scope.row.reviewer}})</el-button>
                            <!--导师-->
                            <span v-else-if="scope.row.status==4 && scope.row.reviewerName">{{scope.row.reviewerName}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :label="$t('message.operating')" fixed="right" width="130">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click="handleDetail(scope)"
                            >{{$t('message.detail')}}</el-button>
                        </template>
                    </el-table-column>
                    <!-- <el-table-column :label="$t('message.operating')" width="60">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                @click=" handleAgentApply(scope.row) "
                            >{{$t('message.apply')}}</el-button>
                        </template>
                    </el-table-column> -->
                </edu-table>
            </el-card>
        </div>
        <div v-show="indexKey == '1'">
            <el-card shadow="never">
                <div v-if="!isSingleStudent">
                    <div class="edu-page-title">学生信息</div>
                    <hr style="margin:10px 0" />
                    <el-form
                        label-position="right"
                        label-width="120px"
                        label-suffix="："
                        id="stu-info"
                        @submit.native.prevent
                    >
                        <el-row :gutter="24">
                            <el-col :span="6">
                                <!-- <el-form-item
                                    :label="$t('label.stuCode')"
                                >{{selectedStudents[0].studentId}}</el-form-item> -->
                                <el-form-item
                                    :label="$t('label.stuCode')"
                                >
                                <el-input
                                    v-model="searchStudentId"
                                    @blur="getOneStu"
                                    style="width:200px"
                                    @keyup.enter.native="getOneStu"
                                >
                                    <i
                                        class="el-icon-search"
                                        slot="suffix"
                                        style="cursor:pointer"
                                        @click="getOneStu"
                                    ></i>
                                </el-input>
                                
                                 </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item
                                    :label="$t('label.stuName')"
                                >{{selectedStudents[0].studentName}}</el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item
                                    :label="$t('label.college')"
                                >{{selectedStudents[0].facultyI18n}}</el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item
                                    :label="$t('label.major')"
                                >{{selectedStudents[0].professionI18n}}</el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="24">
                            <el-col :span="6">
                                <el-form-item
                                    :label="$t('label.grade')"
                                >{{selectedStudents[0].grade}}</el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="导师">{{selectedStudents[0].teacher}}</el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item
                                    :label="$t('label.trainingLevel')"
                                >{{selectedStudents[0].trainingLevelI18n}}</el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item
                                    :label="$t('label.trainingCategory')"
                                >{{selectedStudents[0].trainingCategoryI18n}}</el-form-item>
                            </el-col>
                            </el-row>
                            <el-row :gutter="24">
                            <el-col :span="6">
                                <el-form-item
                                    :label="$t('dic.degreeType')"
                                >{{selectedStudents[0].degreeTypeI18n}}</el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item
                                    :label="$t('label.formLearning')"
                                >{{selectedStudents[0].formLearningI18n}}</el-form-item>
                            </el-col>
                            <el-col :span="6" v-if="defenseType == 1">
                                <el-form-item
                                    :label="$t('label.enrolDate')"
                                >{{selectedStudents[0].enrolDate}}</el-form-item>
                            </el-col>
                            <el-col :span="6" v-if="defenseType == 1">
                                <el-form-item
                                    :label="$t('label.expectedGraduationDate')"
                                >{{selectedStudents[0].expectedGraduationDate}}</el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </div>
                <div v-if="isSingleStudent">
                    <div class="edu-page-title">已选择学生</div>
                    <edu-table
                        :data="selectedStudents"
                        :selection="false"
                        :order="false"
                        :pagination="false"
                        style="margin:10px 0 15px"
                    >
                        <el-table-column :label="$t('message.order')" prop="index" width="50"></el-table-column>
                        <el-table-column
                            :label="$t('label.stuCode')"
                            prop="studentId"
                            show-overflow-tooltip
                            width="110"
                        ></el-table-column>
                        <el-table-column
                            :label="$t('label.stuName')"
                            prop="studentName"
                            width="110"
                            show-overflow-tooltip
                        ></el-table-column>
                        <el-table-column :label="$t('label.grade')" prop="grade"></el-table-column>
                        <el-table-column :label="$t('label.college')" show-overflow-tooltip>
                            <template slot-scope="scope">{{ scope.row.facultyI18n }}</template>
                        </el-table-column>
                        <el-table-column :label="$t('label.major')" show-overflow-tooltip>
                            <template slot-scope="scope">{{ scope.row.professionI18n }}</template>
                        </el-table-column>
                        <el-table-column :label="$t('label.trainingLevel')">
                            <template slot-scope="scope">{{ scope.row.trainingLevelI18n }}</template>
                        </el-table-column>
                        <el-table-column :label="$t('label.trainingCategory')">
                            <template slot-scope="scope">{{ scope.row.trainingCategoryI18n }}</template>
                        </el-table-column>
                        <el-table-column :label="$t('dic.degreeType')" prop="degreeType">
                            <template slot-scope="scope">{{ scope.row.degreeTypeI18n }}</template>
                        </el-table-column>
                        <el-table-column :label="$t('label.formLearning')">
                            <template slot-scope="scope">{{ scope.row.formLearningI18n }}</template>
                        </el-table-column>
                        <el-table-column label="导师" show-overflow-tooltip>
                            <template slot-scope="scope">{{ scope.row.teacher }}</template>
                        </el-table-column>
                    </edu-table>
                </div>
            </el-card>
            <apply-form
                ref="applyForm"
                :students="selectedStudents"
                :defense-type="defenseType"
                :apply-type="applyType"
                :submitType="submitType"
                :mayGraduatTime='mayGraduatTime'
                @close="handleReturn"
                @success="handleSuccess"
            />
        </div>
        <div v-if="indexKey == '2'">
            <el-card shadow="never">
                <div class="edu-page-title">学生信息</div>
                <hr style="margin:15px 0 10px 0" />
                <el-form
                    label-position="right"
                    label-width="120px"
                    label-suffix="："
                    id="stu-info"
                    v-if="currentStudent"
                >
                    <el-row>
                        <el-col :span="colSpan">
                            <el-form-item :label="$t('label.stuCode')">{{currentStudent.studentId}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.stuName')"
                            >{{currentStudent.studentName}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.college')"
                            >{{currentStudent.facultyI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.major')"
                            >{{currentStudent.professionI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item :label="$t('label.grade')">{{currentStudent.grade}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item label="导师">{{currentStudent.teacher}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.trainingLevel')"
                            >{{currentStudent.trainingLevelI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.trainingCategory')"
                            >{{currentStudent.trainingCategoryI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('dic.degreeType')"
                            >{{currentStudent.degreeTypeI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.formLearning')"
                            >{{currentStudent.formLearningI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan" v-if="defenseType == 1">
                                <el-form-item
                                    :label="$t('label.enrolDate')"
                                >{{currentStudent.enrolDate}}</el-form-item>
                            </el-col>
                            <el-col :span="colSpan" v-if="defenseType == 1">
                                <el-form-item
                                    :label="$t('label.expectedGraduationDate')"
                                >{{currentStudent.expectedGraduationDate}}</el-form-item>
                            </el-col>
                    </el-row>
                </el-form>
                <!--详情-->
                <div v-if="currentOprType==oprType.READ">
                    <hr style="margin:0 0 15px 0" />
                    <div class="edu-page-title">申请明细</div>
                    <table class="table-detail">
                        <col width="15%" />
                        <col width="85%" />
                        <tr>
                            <td class="label">
                                <span>预计{{title}}答辩时间：</span>
                            </td>
                            <td>
                                <span>{{currentStudent.defenseTime}}</span>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <span>原因说明：</span>
                            </td>
                            <td>
                                <span>{{currentStudent.reasonDesc}}</span>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <span>申请材料：</span>
                            </td>
                            <td>
                                <!-- <div
                                    :key="index"
                                    v-for="(file,index) in currentStudent.attachFile"
                                >
                                    <span>
                                        <a
                                            href="#"
                                            @click="handleDownLoad(file)"
                                        >{{getFileName(file.name)}}</a>
                                    </span>
                                </div> -->
                                <PreviewOffice
                                :newFileList="currentStudent.attachFile"
                                />
                            </td>
                        </tr>
                    </table>
                </div>
            </el-card>
            <el-card shadow="never" v-if="currentStudent&&currentStudent.workflowNo">
                <div class="edu-page-title">审批进度</div>
                <edu-table
                    key="prograss"
                    :pagination="false"
                    style="margin-top:10px"
                    :selection="false"
                    :data="approvalHistorys"
                >
                    <el-table-column :label="$t('message.time')" prop="approvalTime" />
                    <el-table-column label="审批人" prop="reviewerName" />
                    <el-table-column :label="$t('label.operation')" prop="processOperat" />
                    <el-table-column label="节点" prop="processNodes" />
                    <el-table-column label="说明" prop="reasonDescri" show-overflow-tooltip />
                </edu-table>
            </el-card>
        </div>
        <edu-dialog
            title="组内用户明细"
            ref="groupUsers"
            width="800px"
            @close="handleGroupUsersClose"
            :showFooter="false"
        >
            <edu-table
                key="users"
                :data="users"
                size="mini"
                style="width:100%"
                @page-change="handleUserCurrentChange"
                :total="usersQueryForm.total_"
                :pageSize="usersQueryForm.pageSize_"
                :pageNum="usersQueryForm.pageNum_"
                :selection="false"
            >
                <el-table-column label="账号" prop="studentId" width="100"></el-table-column>
                <el-table-column label="用户名" prop="name" width="100"></el-table-column>
                <el-table-column label="联系电话" prop="phoneNumber" show-overflow-tooltip></el-table-column>
                <el-table-column label="联系邮箱" prop="email" show-overflow-tooltip></el-table-column>
                <el-table-column label="类型" width="80">
                    <template slot-scope="scope">{{getUserType(scope.row.userType)}}</template>
                </el-table-column>
            </edu-table>
        </edu-dialog>
    </div>
</template>
<script>
import { queryDic } from "common/src/api/dictionary";
import { selectOralDefense, oralApprovalHistory } from "common/src/api/culture/change";
import { downloadfile } from "common/src/api/upload";
import stu from 'common/src/api/studentinfo'
import { getUserInfoListByGroupId } from "common/src/api/user";
import ApplyForm from "./ApplyForm";
import PreviewOffice from "common/src/components/common/PreviewOffice.vue"
import mixin from 'common/src/mixins/index';
export default {
    name: "AgentApply",
    mixins: [mixin],
    props: {
        type: {
            default: null,
            required: true
        },
        defenseType: {
            default: null,
            required: true
        },
        applyType: {
            default: null,
            required: true
        },
        agencyApplyType: {
            default: null,
            required: true
        },
        submitType: {
            default: 0,
            required: true
        }
    },
    components: {
        ApplyForm,
        PreviewOffice
    },
    data: function() {
        return {
            tableTitle: this.defenseType == 0 ? "提前" : "延期",
            title: null,
            currentOprType: null,
            mayGraduatTime: null,
            approvalHistorys: null,
            oprType: {
                READ: "0", //详情
            },
            queryForm: {
                defenseType: 0, //0-提前答辩  1-延迟答辩
                applyType: null,
                agencyApplyType: null,
                grade: null,
                faculty: [],
                profession: [],
                trainingLevel: null,
                trainingCategory: null,
                degreeType: null,
                formLearning: null,
                enrolMethods: null,
                enrolMethodList: [],
                status: [],
                keyWord: null,
                pageSize_: 20,
                pageNum_: 1,
                total_: 0
            },
            options: {
                faculty: [],
                profession: [],
                trainingLevel: [],
                trainingCategory: [],
                degreeType: [],
                formLearning: [],
                enrolMethods: [],
                approveStatus: [
                    {
                    label: "草稿",
                    value: "0"
                },
                {
                    label: "驳回",
                    value: "2"
                },
                {
                    label: "通过",
                    value: "3"
                },
                {
                    label: "导师审核",
                    value: "4"
                },
                {
                    label: "学院审核",
                    value: "5"
                },
                {
                    label: "留办审核",
                    value: "6"
                },
                {
                    label: "培养处审核",
                    value: "7"
                }
                ]
            },
            students: null,
            searchStudentId: '',
            indexKey: "0",
            users: null,
            usersQueryForm: {
                groupId: null,
                pageSize_: 20,
                pageNum_: 1,
                total_: 0
            },
            breadPath: {
                label: null,
                key: "0",
                children: [
                    {
                        key: "1",
                        label:
                            this.type == "1" ? "管理员代申请" : "教务员代申请"
                    },
                    {
                        key: "2",
                        label: ''
                    }
                ]
            },
            selectedStudents: [
                {
                    studentName:'',
                    facultyI18n: '',
                    professionI18n: '',
                    grade: '',
                    teacher:'',
                    teacherId: '',
                    trainingLevelI18n: '',
                    trainingCategoryI18n: '',
                    degreeTypeI18n: '',
                    formLearningI18n: '',
                    enrolMethodsI18n: '',
                }
            ],
            formStudents: null
        };
    },
    computed: {
        isSingleStudent: function() {
            return this.selectedStudents && this.selectedStudents.length > 1
                ? true
                : false;
        },
        colSpan() {
            if (
                this.selectedStudents == null ||
                this.selectedStudents.length != 1
            ) {
                return 6;
            }

            if (
                this.selectedStudents[0].facultyI18n &&
                this.selectedStudents[0].facultyI18n.length >= 8
            ) {
                return 8;
            }
            if (
                this.selectedStudents[0].professionI18n &&
                this.selectedStudents[0].professionI18n.length >= 8
            ) {
                return 8;
            }
            return 6;
        }
    },
    mounted() {
        this.title =
            this.defenseType == 0 ? "提前答辩代申请列表" : "延迟答辩代申请列表";
        this.breadPath.label = this.defenseType == 0 ? "提前答辩" : "延迟答辩";
        this.queryForm.defenseType = this.defenseType;
        this.queryForm.applyType = this.applyType;
        this.queryForm.agencyApplyType = this.agencyApplyType;
        this.init();
    },
    methods: {
        init() {
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: [
                    "X_YX",
                    "X_PYCC",
                    "X_PYLB",
                    "X_XWLX",
                    "X_XXXS",
                    "X_RXFS",
                    "K_SQYY",
                    "X_RXJJ"
                ]
            };
            queryDic(data).then(res => {
                if (res.code === 200) {
                    this.fill("faculty", res.data.X_YX);
                    this.fill("trainingLevel", res.data.X_PYCC);
                    this.fill("trainingCategory", res.data.X_PYLB);
                    this.fill("degreeType", res.data.X_XWLX);
                    this.fill("formLearning", res.data.X_XXXS);
                    this.fill("enrolMethods", res.data.X_RXFS);
                }
            });
            this.onSubmit();
        },
        fill(type, data) {
            for (const key in data) {
                this.options[type].push({
                    value: key,
                    label: data[key]
                });
            }
        },
        reset() {
            // this.queryForm.grade = null;
            // this.queryForm.faculty = [];
            // this.queryForm.profession = [];
            // this.queryForm.trainingLevel = null;
            // this.queryForm.trainingCategory = null;
            // this.queryForm.degreeType = null;
            // this.queryForm.formLearning = null;
            // this.queryForm.enrolMethods = null;
            // this.queryForm.keyWord = null;
            // this.options.profession.length = 0;
            this.queryForm.grade = null;
            this.queryForm.faculty = [];
            this.queryForm.profession = [];
            this.queryForm.trainingLevel = null;
            this.queryForm.trainingCategory = null;
            this.queryForm.degreeType = null;
            this.queryForm.formLearning = null;
            this.queryForm.enrolMethodList = [];
            this.queryForm.status = [];
            this.queryForm.keyWord = null;
            this.options.profession.length = 0;
            this.onSubmit();
        },
        onSubmit(isFirstPage = true) {
            if (isFirstPage) {
                this.queryForm.pageNum_ = 1;
            }
            let params = _.cloneDeep(this.queryForm);
            params.faculty =
                params.faculty.length > 0 ? params.faculty.join(",") : null;
            params.profession =
                params.profession.length > 0
                    ? params.profession.join(",")
                    : null;
            params.status =
                params.status.length > 0 ? params.status.join(",") : null;
            params.applyBy = this.global.currentUser.name + "("+ this.global.currentUser.uid + ")" 
            selectOralDefense(params).then(res => {
                if (res.code == 200) {
                    res.data.list.forEach((row, index) => {
                        row.index_ =
                            this.queryForm.pageSize_ *
                                (this.queryForm.pageNum_ - 1) +
                            index +
                            1;
                    });
                    this.students = res.data.list;
                    this.queryForm.total_ = res.data.total_;
                }
            });
        },
        getFormatData(data) {
            return moment(data).format("YYYY-MM-DD");
        },
        handleDownLoad(file) {
            // downloadfile(file);
            let url = '/api/commonservice/obsfile/downloadfile?objectkey=' + file.url  
            stu.downTemplate(file.name, url);
        },
        getFileName(path) {
            if (path.indexOf("/") != -1) {
                return path.substring(path.lastIndexOf("/") + 1);
            } else {
                return path;
            }
        },
        handleDetail(scope) {
            this.breadPath.children[1].label = this.$t("message.detail");
            this.currentStudent = _.cloneDeep(scope.row);
            if(scope.row.attachFile && scope.row.attachFile.length > 0) {
        if((scope.row.attachFile.substring(0,1)).toString() === '[') {
          this.currentStudent.attachFile = JSON.parse(scope.row.attachFile)
        } else {
          let filesList = []
          let evidList = scope.row.attachFile.split(",")
          evidList.map(files=> {
            filesList.push(
              {
                name: files,
                url: files
              }
            )
          })
          this.currentStudent.attachFile = filesList
        }
       }
            this.indexKey = "2";
            this.currentOprType = this.oprType.READ;
            this.currentStudent.defenseTime = moment(
                scope.row.defenseTime
            ).format("YYYY-MM-DD");
            this.bindApproveHistory(scope.row.workflowNo);
        },
        bindApproveHistory(workflowNo) {
            this.approvalHistorys = null;
            let module_ = this.defenseType == 0 ? 2 : 3;
            if (workflowNo) {
                oralApprovalHistory(workflowNo, module_).then(res => {
                    if (res.code == 200) {
                        this.approvalHistorys = res.data;
                    }
                });
            }
        },
         //预览组内用户信息
        handleReviewGroup(groupId) {
            this.$refs.groupUsers.open();
            this.usersQueryForm.groupId = groupId;
            this.getGroupUsersByGroupId();
        },
        //关闭组内用户信息时初始化
        handleGroupUsersClose() {
            this.usersQueryForm.groupId = null;
            this.usersQueryForm.pageNum_ = 1;
            this.usersQueryForm.pageSize_ = 20;
            this.usersQueryForm.total_ = 0;
        },
        //组内用户信息翻页
        handleUserCurrentChange(val) {
            this.usersQueryForm.pageSize_ = val.pageSize;
            this.usersQueryForm.pageNum_ = val.pageNum;
            this.getGroupUsersByGroupId();
        },
        //获取组内用户列表
        getGroupUsersByGroupId(groupId) {
            getUserInfoListByGroupId({
                groupId: this.usersQueryForm.groupId,
                pageNum_: this.usersQueryForm.pageNum_,
                pageSize_: this.usersQueryForm.pageSize_,
                total: 0,
                userName: ""
            }).then(res => {
                if (res.code == 200) {
                    this.users = res.data.list;
                    this.usersQueryForm.total_ = res.data.total_;
                }
            });
        },
        getUserType(val) {
            if (val == 1) {
                return "老师";
            }
            if (val == 2) {
                return "学生";
            }
            if (val == 3) {
                return "本地用户";
            }
            return null;
        },
        getOneStu() {
            let parm = {
                pageSize_: 1,
                pageNum_: 1,
                studentId: this.searchStudentId,
                applyType: 2,
                defenseType: this.defenseType
            }
            if(this.searchStudentId) {
            selectOralDefense(parm).then(res => {
                if (res.code == 200 && res.data && res.data.list.length > 0) {
                    this.selectedStudents = res.data.list;
                    this.mayGraduatTime = res.data.list[0].expectedGraduationDate
                } else {
                    this.$message.error('未查询到学生信息')
                    this.searchStudentId = ''
                    this.selectedStudents = [
                        {
                            studentName:'',
                            facultyI18n: '',
                            professionI18n: '',
                            grade: '',
                            teacher:'',
                            teacherId: '',
                            trainingLevelI18n: '',
                            trainingCategoryI18n: '',
                            degreeTypeI18n: '',
                            formLearningI18n: '',
                            enrolMethodsI18n: '',
                        }
                    ]
                }
            });
        } else {
            this.searchStudentId = ''
            this.selectedStudents = [
                {
                    studentName:'',
                    facultyI18n: '',
                    professionI18n: '',
                    grade: '',
                    teacher:'',
                    teacherId: '',
                    trainingLevelI18n: '',
                    trainingCategoryI18n: '',
                    degreeTypeI18n: '',
                    formLearningI18n: '',
                    enrolMethodsI18n: '',
                }
            ]
        }

        },
        
        handleAgentApply(student) {
            // this.selectedStudents = [student];
            // this.$refs.applyForm.init();
            // this.formStudents = _.cloneDeep(this.selectedStudents);
            // this.indexKey = "1";
            this.indexKey = "1";
            this.$refs.applyForm.init();
            this.searchStudentId = ''
                    this.selectedStudents = [
                        {
                            studentName:'',
                            facultyI18n: '',
                            professionI18n: '',
                            grade: '',
                            teacher:'',
                            teacherId: '',
                            trainingLevelI18n: '',
                            trainingCategoryI18n: '',
                            degreeTypeI18n: '',
                            formLearningI18n: '',
                            enrolMethodsI18n: '',
                        }
                    ]
        },
        handleCurrentChange(val) {
            this.queryForm.pageSize_ = val.pageSize;
            this.queryForm.pageNum_ = val.pageNum;
            this.onSubmit(false);
        },
        handleChangeFaculty() {
            this.options.profession = [];
            this.queryForm.profession = [];
            if (!this.queryForm.faculty) {
                return;
            }
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["G_ZY"],
                filter: {
                    prefix: this.queryForm.faculty,
                    specilaCode: "XY2ZY",
                    grade: null,
                    facultys: this.queryForm.faculty,
                    degreeType: this.queryForm.degreeType
                        ? [this.queryForm.degreeType]
                        : []
                }
            };
            queryDic(data).then(res => {
                if (res.code === 200) this.fill("profession", res.data.G_ZY);
            });
        },
        handleReturn() {
            this.indexKey = "0";
            this.onSubmit();
        },
        handleSuccess() {
            this.indexKey = "0";
            this.onSubmit();
        }
    }
};
</script>

<style lang="scss" scoped>
#stu-info {
    ::v-deep .el-form-item--small.el-form-item {
        margin-bottom: 5px;
    }
}
.table-detail {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #d2d4d6;
    margin-top: 15px;
    td {
        border-collapse: collapse;
        border: 1px solid #d2d4d6;
        line-height: 32px;
    }
    .label {
        text-align: right;
        background: #f5f7f9;
        color: #8896a7;
    }
    span {
        margin: 0 10px;
    }
}
</style>